﻿using System;

namespace Tools.Utilities
{
    public static class NumbericUtils
    {
        public static string ToCurrencyFormat(this double number)
        {
            return number != 0 ? number.ToString("$#,###.00") : "$0.00";
        }

        public static string ToCurrencyFormat(this float? number)
        {
            return number != null ? ToCurrencyFormat(number.Value) : string.Empty;
        }

        public static string ToCurrencyFormat(this decimal? number)
        {
            return number != null ? ToCurrencyFormat(number.Value) : string.Empty;
        }

        public static string ToCurrencyFormat(this float number)
        {
            return number > 0.005 ? number.ToString("$#,##0.00") : "$0.00";
        }

        public static string ToCurrencyFormat(this decimal number)
        {
            return number > new decimal(0.005) ? number.ToString("$#,###.00") : "$0.00";
        }

        public static string ToCurrencyFormatWithNegative(this float number)
        {
            return Math.Abs(number) > 0.005 ? number.ToString("$#,###.00") : "$0.00";
        }

        public static string ToStringPercentFormat(this float number)
        {
            return number > 0.005 ? string.Format("{0}{1}", (number * 100).ToString("#,###.00"), "%") : "0.00%";
        }

        public static string ToStringFormat(this long number)
        {
            return number > 1000 ? number.ToString("0,000") : number.ToString();
        }

        public static string ToStringFormat(this int number)
        {
            return ToStringFormat((long)number);
        }
    }
}
